package com.simoniu.hbase.phoenixjdbc.app;


//import org.apache.phoenix.queryserver.client.ThinClientUtil;
import org.apache.phoenix.queryserver.client.ThinClientUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

public class PhoenixApp {

  public static void main(String[] args) throws Exception {

    Class.forName("org.apache.phoenix.queryserver.client.Driver");
    //Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

    String url = ThinClientUtil.getConnectionUrl("hadoop-master", 8765);
    //String url = "jdbc:phoenix:192.168.2.177:2181";

    System.out.println(url);
    Connection connection = DriverManager.getConnection(url);
    PreparedStatement statement = connection.prepareStatement("select * from STUDENTS");
    ResultSet resultSet = statement.executeQuery();

    while (resultSet.next()) {
      System.out.println(resultSet.getInt("SID")+","+resultSet.getString("SNAME")+","+resultSet.getInt("AGE")+","+resultSet.getString("GENDER"));
    }

    statement.close();
    connection.close();
  }

}
